import type {
  UserInfo,
  CodeType,
  User,
  PatientList,
  Patient
} from '@/types/user'
import { request } from '@/utils/request'

/**
 * 密码登录
 * @param mobile 手机号
 * @param password 密码
 * @returns 用户信息
 */
export const loginByPassword = (mobile: string, password: string) =>
  request<User>('/login/password', 'POST', { mobile, password })

/**
 * 获取短信验证码
 * @param mobile 手机号
 * @param type 验证码的作用类型
 * @returns 验证码
 */
export const sendMobileCode = (mobile: string, type: CodeType) =>
  request<{ code: string }>('/code', 'GET', { mobile, type })

/**
 * 验证码登录
 * @param mobile 手机号
 * @param code 验证码
 * @returns 用户信息
 */
export const loginByCode = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

/**
 * 获取个人用户中心的数据
 * @returns 用户信息
 */
export const getUserInfo = () => request<UserInfo>('/patient/myUser')

/**
 * 获取患者列表
 * @returns 患者列表信息
 */
export const getPatientList = () => {
  return request<PatientList>('/patient/mylist')
}

/**
 * 添加患者
 * @param patient
 * @returns
 */
export const addPatientList = (patient: Patient) => {
  return request<{ id: string }>('/patient/add', 'POST', patient)
}

/**
 * 编辑患者信息
 * @param patient
 * @returns
 */
export const editPatient = (patient: Patient) =>
  request('/patient/update', 'PUT', patient)

/**
 * 删除患者信息
 * @param id
 * @returns
 */
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

// 查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>(`/patient/info/${id}`)

/**
 * 登录QQ
 * @param openId
 * @returns
 */
export const loginByQQ = (openId: string) =>
  request<User>('/login/thirdparty', 'POST', { openId, source: 'qq' })

// 手机绑定
export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>('/login/binding', 'POST', data)
